home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-23 | 59.0 KB | 1,772 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTwistDownView.cp
- // ETO20 MacApp 3.3.1, MPW 3.4.1
- // Copyright ©1994-1996 Conrad Kopala
- // Twist Down Lists version 2.0a0 7/15/96
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTWISTDOWNVIEW__
- #include "UTwistDownView.h"
- #endif
-
- #ifndef __UTWISTDOWNAPP__
- #include "UTwistDownApp.h"
- #endif
-
- #ifndef __UTWISTDOWNDOCUMENT__
- #include "UTwistDownDocument.h"
- #endif
-
- #ifndef __UTWISTDOWNELEMENT__
- #include "UTwistDownElement.h"
- #endif
-
- #ifndef __UTWISTDOWNCONTROL__
- #include "UTwistDownControl.h"
- #endif
-
- //MacApp stuff
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- //ToolBox stuff
- #ifndef __FONTS__
- #include "Fonts.h"
- #endif
-
- #ifndef __QUICKDRAWTEXT__
- #include "QuickdrawText.h"
- #endif
-
- #ifndef __SCRIPT__
- #include "Script.h"
- #endif
-
- #ifndef __AEREGISTRY__
- #include "AERegistry.h"
- #endif
-
- //ANSI stuff
- //None
- //----------------------------------------------------------------------------------------
- // Constants:
-
-
- //========================================================================================
- // Global Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUTwistDownView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void InitUTwistDownView()
- {
-
- MA_REGISTER_CLASS(TTwistDownView);
- MA_REGISTER_CLASS(TChangeFontSizeDialog);
-
- }
-
- //========================================================================================
- // CLASS TTwistDownView
- //========================================================================================
- #undef Inherited
- #define Inherited TTextListView
-
- #pragma segment GVOpen
- MA_DEFINE_CLASS_M2(TTwistDownView, Inherited, MScriptableObject);
- //----------------------------------------------------------------------------------------
- // TTwistDownView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
- TTwistDownView::TTwistDownView(): MScriptableObject(cTwistDownView)
- {
- fTwistDownDocument = NULL;
- fTwistDownControlSize = gZeroVPt;
-
- fOpenTriangle = NULL;
- fClosedTriangle = NULL;
- fIntermediateTriangle = NULL;
-
- fCouldExpandAll = FALSE;
- fCouldCollapseAll = FALSE;
-
- fHandlesFirstClicks = FALSE;
- fIsFirstClick = TRUE;
-
- fNumberOfControls = 0;
- fInitialNumberOfControls = 0;
- fNumberOfExpandedControls = 0;
- fNumberOfCollapsedControls = 0;
-
- fControlCountingEnabled = FALSE;
-
- fWritingDirection = leftToRight; //assume left to right
- fTwistDownControlLocation.v = 0;
- fTwistDownControlLocation.h = 0;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::~TTwistDownView
- //----------------------------------------------------------------------------------------
- #pragma segment GVClose
- TTwistDownView::~TTwistDownView()
- {
-
- fTwistDownDocument = NULL;
- fTwistDownControlSize = gZeroVPt;
-
- if (fOpenTriangle)
- {
- KillPoly(fOpenTriangle);
- fOpenTriangle = NULL;
- }
-
- if (fClosedTriangle)
- {
- KillPoly(fClosedTriangle);
- fClosedTriangle = NULL;
- }
-
- if (fIntermediateTriangle)
- {
- KillPoly(fIntermediateTriangle);
- fIntermediateTriangle = NULL;
- }
-
- fCouldExpandAll = FALSE;
- fCouldCollapseAll = FALSE;
-
- fNumberOfControls = 0;
- fInitialNumberOfControls = 0;
- fNumberOfExpandedControls = 0;
- fNumberOfCollapsedControls = 0;
-
- fControlCountingEnabled = FALSE;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::ITwistDownView:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownView::ITwistDownView(TTwistDownDocument* itsTwistDownDocument, TView* itsSuperView,
- const VPoint& itsLocation, const VPoint& itsSize)
- {
-
- short numOfItems = 0; // Number of items initially
- short rowHeight = 0; // Row height, or zero for font height
- short colWidth = 200; // Width of items in the columns
- Boolean adornRows = FALSE; // Draw the row adornments?
- Boolean adornCols = FALSE; // Draw the col adornment?
- short rowInset = 0; // Amount to inset the rows
- short colInset = 0; // Amount to inset the column
- Boolean singleSelection = TRUE; // single cell selection?
-
- this -> ITextListView(itsTwistDownDocument,itsSuperView,itsLocation,itsSize,sizeVariable,sizeVariable,
- numOfItems,rowHeight,colWidth,adornRows,adornCols,rowInset,colInset,singleSelection,
- gApplicationStyle);
-
- fTwistDownDocument = itsTwistDownDocument;
-
- //Let's set the fWritingDirection to the current system direction.
- if (GetSysDirection() == 0)
- fWritingDirection = leftToRight;
- else
- fWritingDirection = rightToLeft;
-
- if (fWritingDirection == leftToRight)
- fJustification = teFlushDefault;
- else
- fJustification = teFlushRight;
-
- this -> CreateTwistDownTriangles();
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownView::DoPostCreate(TDocument* itsDocument)
- {
-
- Inherited::DoPostCreate(itsDocument);
- fTwistDownDocument = (TTwistDownDocument*)itsDocument;
-
- //Let's set the fWritingDirection to the current system direction.
- if (GetSysDirection() == 0)
- fWritingDirection = leftToRight;
- else
- fWritingDirection = rightToLeft;
-
- if (fWritingDirection == leftToRight)
- fJustification = teFlushDefault;
- else
- fJustification = teFlushRight;
-
- FailInfo fi;
- Try(fi)
- {
- this -> CreateTwistDownTriangles();
- OSErr myOSErr = noErr;
-
- if (fTwistDownDocument)
- myOSErr = this -> CreateVisibleList();
-
- if (myOSErr != noErr)
- Failure(myOSErr, 0);
-
- fi.Success();
- }
- else // Recover
- {
- fi.ReSignal();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::DoSetupMenus()
- {
- long numberOfItemsInList = 0;
-
- //The average user will probably never encounter a situation where the list is empty.
- //However, I can make a volume that is empty and so, I figure there is at least one
- //other malicious person out there who will do it too. Using your favorite disk editor,
- //set all IsInvisible flags. When you open the disk in Twist Down Lists, it will appear
- //to be empty unless you set Twist Down Lists to Show Invisibles.
-
- if (fTwistDownDocument)
- numberOfItemsInList = fTwistDownDocument -> GetNumberOfItemsInList();
-
- MenuRef aMenuRef;
- TextStyle aStyle;
- CStr255 aName;
- short theFont;
- short nItems;
- Style aFace;
-
- Inherited::DoSetupMenus();
-
- Boolean haveMemory = !MemSpaceIsLow();
-
- aStyle = fTextStyle;
-
- aMenuRef = MAGetMenu(mFontMenu);
-
- //Font menu setup copied from DemoText:UTEDocument.cp
- if (aMenuRef)
- {
-
- GetFontName(aStyle.tsFont, aName); // Get real font number in case tsFont is
- GetFNum(aName, &theFont); // …the system or application font.
- nItems = CountMItems(aMenuRef);
- for (short item = 1; item <= nItems; ++item)
- {
- if (item <= 31)
- EnableItem(aMenuRef, item);
-
- short fnt;
-
- GetMenuItemText(aMenuRef, item, aName);
- GetFNum(aName, &fnt);
- CheckItem(aMenuRef, item, (fnt == theFont));
-
- }
- }
-
- //Note: The cFont commands are enabled only if there is something in the list.
- Enable(cFont, numberOfItemsInList > 0);
-
- //Note: Font size menu setup copied from DemoText:UTEDocument.cp
- for (CommandNumber c = cFontSizeMin; c <= cFontSizeMax; ++c)
- {
- Boolean checkSize;
-
- checkSize = ((c - cFontSizeBase) == aStyle.tsSize);
-
- EnableCheck(c, numberOfItemsInList > 0, checkSize);
-
- if (RealFont(aStyle.tsFont, (short) (c - cFontSizeBase)))
- aFace = outline; // …then we outline it
- else
- aFace = 0;
-
- SetStyle(c, aFace);
- }
-
- //Note: The cLargerFontSize, cSmallerFontSize, and cOtherFontSize commands are enabled
- //only if there is something in the list.
- Enable(cLargerFontSize, numberOfItemsInList > 0);
- Enable(cSmallerFontSize, numberOfItemsInList > 0);
- Enable(cOtherFontSize, numberOfItemsInList > 0);
-
- Enable(cExpandAll, fCouldExpandAll);
- Enable(cCollapseAll, fCouldCollapseAll); //This should always be available except
- //when the list is already collapsed because
- //it can help the user get out of a low
- //memory situation.
-
- CStr255 menuItemName = gEmptyString;
-
- if (fWritingDirection == leftToRight)
- SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kRightToLeftNameIdx);
- else if(fWritingDirection == rightToLeft)
- SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kLeftToRightNameIdx);
-
- Enable(cWritingDirection, !gUseSystemDirection && numberOfItemsInList > 0);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TTwistDownView::DoMenuCommand(CommandNumber aCommandNumber)
- {
-
- CStr255 newFontName;
- short menu;
- short item;
- short newFontSize;
- TextStyle newStyle;
-
- newStyle = fTextStyle;
-
- //Note: DoMenuCommand for mFontMenu follows after DemoText:UTEDocument.cp
- CommandToMenuItem(aCommandNumber, menu, item);
-
- if (menu == mFontMenu)
- {
- GetMenuItemText(MAGetMenu(menu), item, newFontName);
- GetFNum(newFontName, &(newStyle.tsFont));
-
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pFontName);
- CTempDesc theNewFont;
- theNewFont.PutString(newFontName);
- theEvent -> WriteParameter(keyAEData, theNewFont);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- this -> DoChangeFont(newFontName);
- }
-
- //Note: The following else if clause follows after DemoText:UTEDocument.cp except for the fact
- //that DemoText doesn't do AppleEvents.
- else if ((aCommandNumber > cFontSizeBase) && (aCommandNumber <= cFontSizeMax))
- {
-
- newFontSize = (short)(aCommandNumber - cFontSizeBase);
-
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pPointSize);
- CTempDesc theNewFontSize;
- long theFontSize = long(newFontSize);
- theNewFontSize.PutLong(theFontSize);
- theEvent -> WriteParameter(keyAEData, theNewFontSize);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- this -> DoChangeFontSize(newFontSize);
-
- }
- else
- switch (aCommandNumber)
- {
- //Note: These two cases follow after DemoText:UTEDocument.cp cGrowSize and cGrowShrink.
- //Except for the fact that DemoText doesn't do AppleEvents.
- case cLargerFontSize:
- case cSmallerFontSize:
- {
- //Note that no limits are put on newFontSize. That's because it's fun and
- //it hasn't broken anything yet.
- newFontSize = fTextStyle.tsSize;
- if (aCommandNumber == cLargerFontSize)
- newFontSize = newFontSize + 1;
- else
- newFontSize = newFontSize - 1;
-
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pPointSize);
- CTempDesc theNewFontSize;
- long theFontSize = long(newFontSize);
- theNewFontSize.PutLong(theFontSize);
- theEvent -> WriteParameter(keyAEData, theNewFontSize);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- this -> DoChangeFontSize(newFontSize);
- }
- break;
-
- //Note: DemoText:UTEDocument.cp hasn't implemented cOtherFontSize (cOtherSize) yet (as of ETO19)
- case cOtherFontSize:
- {
- long fontSize = 0;
- fontSize = (long)newStyle.tsSize;
-
- if (this -> GetNewFontSize(cOtherFontSize,fontSize))
- {
- newFontSize = (short)fontSize;
-
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pPointSize);
- CTempDesc theNewFontSize;
- long theFontSize = long(newFontSize);
- theNewFontSize.PutLong(theFontSize);
- theEvent -> WriteParameter(keyAEData, theNewFontSize);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- this -> DoChangeFontSize(newFontSize);
- }
- } //end case cOtherFontSize
- break;
-
- case cExpandAll:
- {
- //There is no need to check fCouldExpandAll here because this is a menu command.
- //If the cExpandAll command is enabled it is ok to do it.
- TExpandAllCommand* anExpandAllCommand = new TExpandAllCommand;
- anExpandAllCommand -> IExpandAllCommand(fTwistDownDocument, this);
- if (gSendAppleEvents)
- anExpandAllCommand -> fUseAppleEvent = TRUE;
- this -> PostCommand(anExpandAllCommand);
- } //end case cExpandAll
- break;
-
- case cCollapseAll:
- {
- //There is no need to check fCouldCollapseAll here because this is a menu command.
- //If the cCollapseAll command is enabled it is ok to do it.
- //Because we don't want this to fail for out of memory reasons,
- //allocate it from temporary memory. //PGMacApp 550
- Boolean oldTemp = TemporaryAllocation(TRUE);
- Boolean oldArrayPerm = AllocateObjectsFromPerm(FALSE);
- TCollapseAllCommand* aCollapseAllCommand = new TCollapseAllCommand;
- aCollapseAllCommand -> ICollapseAllCommand(fTwistDownDocument, this);
- if (gSendAppleEvents)
- aCollapseAllCommand -> fUseAppleEvent = TRUE;
- this -> PostCommand(aCollapseAllCommand);
- oldArrayPerm = AllocateObjectsFromPerm(oldArrayPerm);
- oldTemp = TemporaryAllocation(oldTemp);
- } //end case cCollapseAll
- break;
-
- case cWritingDirection:
- {
- EWritingDirection newWritingDirection;
- if (fWritingDirection == rightToLeft)
- newWritingDirection = leftToRight;
- else if (fWritingDirection == leftToRight)
- newWritingDirection = rightToLeft;
-
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
- {
- TSetPropertyEvent *theEvent = new TSetPropertyEvent;
- theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pWritingDirection);
- CTempDesc theNewWritingDirection;
-
- if (newWritingDirection == leftToRight)
- theNewWritingDirection.PutEnum(kAELeftToRight);
- else if (newWritingDirection == rightToLeft)
- theNewWritingDirection.PutEnum(kAERightToLeft);
-
- theEvent -> WriteParameter(keyAEData, theNewWritingDirection);
- TAppleEvent * theReply = theEvent -> Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- else
- this -> DoChangeWritingDirection(newWritingDirection);
-
- }
- break;
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- } //end switch
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::HandleMouseDown:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- Boolean TTwistDownView::HandleMouseDown(const VPoint& theMouse,TToolboxEvent* event,
- CPoint hysteresis,EMouseDownType mouseDownType)
-
- {
- //This is saved here so TTwistDownControl::DoMouseUp can know if a mouseUp event
- //is associated with a first click mouseDown event. It it is, TTwistDownControl::DoMouseUp
- //will swallow the mouseUp event.
-
- fIsFirstClick = (mouseDownType == kFirstClick_dragOnly || mouseDownType == kFirstClick_dragOrClick);
-
- return Inherited::HandleMouseDown(theMouse,event,hysteresis,mouseDownType);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetViewSize:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::GetViewSize(VPoint& viewSize)
- {
- viewSize = fSize;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::CreateVisibleList: used by TTwistDownView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- OSErr TTwistDownView::CreateVisibleList()
- {
- OSErr myOSErr = noErr;
-
- myOSErr = this -> BuildVisibleList( 0); //I'd be very surprised if we ever got an error here!
-
- if (myOSErr == noErr)
- {
- short rowNumber = 0;
-
- this -> AddTwistDownControls(fTwistDownDocument -> GetHeadOfList(), rowNumber, myOSErr);
-
- if (myOSErr == noErr)
- {
- this -> ResizeTwistDownViewRows();
- fControlCountingEnabled = TRUE;
- //Now set the enabling conditions for cExpandAll and cCollapseAll
- this -> SetTheCouldFlags();
- }
- }
-
- return myOSErr;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::BuildVisibleList: used by
- // TTwistDownView::CreateVisibleList
- // TTwistDownDocument::ExpandElement
- // TTwistDownDocument::CollapseElement
- // TTwistDownDocument::ExpandAll
- // TTwistDownDocument::CollapseAll
- // TExpandAllCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- OSErr TTwistDownView::BuildVisibleList(short rowNumber)
- {
- OSErr myOSErr = noErr;
- long numberOfRows = 0; //How many we need to show
- short currentNumberOfRows = 0; //How many are in the list
- short numberOfRowsToInsert = 0;
- short numberOfRowsToDelete = 0;
-
- currentNumberOfRows = fNumOfRows;
-
- numberOfRows = fTwistDownDocument -> CountVisibleElements(fTwistDownDocument -> GetHeadOfList());
-
- if (numberOfRows <= (long)kMaxNumberOfItemsToDisplay)
- {
- if (currentNumberOfRows == 0) //we're starting out
- {
- numberOfRowsToInsert = (short)numberOfRows;
- this -> InsItemLast(numberOfRowsToInsert);
- }
- else
- {
- if (currentNumberOfRows > (short)numberOfRows) //we're collapsing the list
- {
- numberOfRowsToDelete = currentNumberOfRows - (short)numberOfRows;
- this -> DelItemAt(rowNumber, numberOfRowsToDelete);
- }
- else if (currentNumberOfRows < (short)numberOfRows) //we're expanding the list
- {
- numberOfRowsToInsert = (short)numberOfRows - currentNumberOfRows;
- if (rowNumber > currentNumberOfRows)
- this -> InsItemLast(numberOfRowsToInsert); //The last element is being expanded.
- else
- this -> InsItemBefore(rowNumber, numberOfRowsToInsert);
-
- }
- else
- {
- // Do nothing, currentNumberOfRows == (short)numberOfRows -- an empty folder.
- }
- }
- }
- else
- myOSErr = errTooManyRows;
-
- return myOSErr;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::ResizeTwistDownViewRows:
- //----------------------------------------------------------------------------------------
- //This adjusts the size of the view to accomodate the precise number of rows in the view.
- #pragma segment ARes
- void TTwistDownView::ResizeTwistDownViewRows()
- {
-
- short rowHeight = 0;
- VPoint viewSize = gZeroVPt;
- short numberOfRows = 0;
- VRect viewRect = gZeroVRect;
- long numberOfItemsInList = fTwistDownDocument -> GetNumberOfItemsInList();
- short newColumnWidth = 0;
-
- if (numberOfItemsInList > 0)
- {
- this -> GetViewSize(viewSize);
- rowHeight = this -> GetRowHeight(1);
- viewSize.v = (VCoordinate)(rowHeight * fNumOfRows);
- }
-
-
- this -> Resize(viewSize, TRUE);
-
- viewRect.right = viewSize.h;
- viewRect.bottom = viewSize.v;
- this -> InvalidateVRect(viewRect);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::CalculateColumnWidth:
- //----------------------------------------------------------------------------------------
- //The intent of this routine is to intelligently set the column width of the twistDownView.
- //It has been tested but is not currently being used.
- #pragma segment ARes
- short TTwistDownView::CalculateColumnWidth()
- {
- short maxIndentLevel = 0;
- short maxTextWidth = 0;
- short newColumnWidth = 0;
-
- fTwistDownDocument -> CalculateColWidthParams(fTwistDownDocument -> GetHeadOfList(),maxIndentLevel,maxTextWidth);
-
- newColumnWidth = (maxIndentLevel + 1)*(short)fTwistDownControlSize.h + maxTextWidth;
-
- if (newColumnWidth >= kMaxShort)
- newColumnWidth = kMaxShort;
-
- return newColumnWidth;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView:::RevealRight:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::RevealRight(Boolean redraw)
- {
- //This routine can be made to work better.
- VPoint thePoint = gZeroVPt;
- thePoint.h = fSize.h;
-
- this -> RevealRect(VRect(fSize.h,gZeroVPt.v,fSize.h,gZeroVPt.v),thePoint, redraw);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::SuperViewChangedFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::SuperViewChangedFrame(const VRect& oldFrame,const VRect& newFrame,Boolean invalidate)
- {
- //When the size of the TWindow holding this twistDownView is changed and, in particular, if
- //the writingDirection is right-to-left, it is necessary that the twistDownControls in this
- //view be pinned to the right side of the twistDownView and consequently the right side of the
- //TWindow holding this view. This is where that is done by setting fTwistDownControlLocation.h
- //to the proper value.
-
- //At present, when windows are resized, it is done on the right side of the window. It will
- //be interesting to see how this works when windows can be resized from either the left or right side.
-
- Inherited:: SuperViewChangedFrame(oldFrame,newFrame,invalidate);
-
- //The following code can be made much more elegant.
- if (fWritingDirection == leftToRight)
- {
- fTwistDownControlLocation.h = 0;
- this -> RevealTop(kRedraw);
- }
- else
- {
- if (this -> GetItemWidth() < (short)fSize.h)
- this -> SetItemWidth((short)fSize.h);
- else if (this -> GetItemWidth() > kMaxShort)
- this -> SetItemWidth(kMaxShort);
-
- fTwistDownControlLocation.h = fSize.h - fTwistDownControlSize.h;
- this -> RevealRight(kRedraw);
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::NewTwistDownControl: used by TTwistDownView::AddTwistDownControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownControl* TTwistDownView::NewTwistDownControl(TTwistDownElement* twistDownElement, VPoint& itsLocation, OSErr& myOSErr)
- {
- TTwistDownControl* newTwistDownControl = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- FailNIL(newTwistDownControl = new TTwistDownControl);
- newTwistDownControl -> ITwistDownControl(itsLocation, twistDownElement, this);
-
- //Note: To properly use the FailHere type test, always initialize the object whose failure
- //you're simulating before signalling Failure(errFailHere, 0);. If you don't the failure recovery
- //won't work when it attempts to free the object.
- if (gFailHere)
- {
- CStr63 failHereText = "FailHere";
- CStr63 displayedText = gEmptyString;
- twistDownElement -> GetDisplayedText(displayedText);
- if (failHereText == displayedText)
- Failure(errFailHere, 0);
- }
-
- if (newTwistDownControl != NULL && twistDownElement -> TestShowSubListFlag())
- fNumberOfExpandedControls++; //We're adding a control that should be shown expanded.
- else
- fNumberOfCollapsedControls++; //We're adding a control that should be shown collapsed.
-
- fi.Success();
- }
- else
- {
- myOSErr = fi.error;
- newTwistDownControl = (TTwistDownControl*)(FreeIfObject(newTwistDownControl));
- //Don't ReSignal because we may be deep in the recursive AddTwistDownControls
- //and we need to back out of a failure gracefully.
- }
-
- return newTwistDownControl;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::AddTwistDownControls: used by
- // TTwistDownView::CreateVisibleList:
- // TTwistDownDocument::ExpandElement:
- // TExpandAllCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::AddTwistDownControls(TTwistDownElement* twistDownElement, short &rowNumber, OSErr& myOSErr)
- {
-
- VRect theVRect = gZeroVRect;
- VPoint twistDownControlLocation = gZeroVPt;
- TTwistDownControl* twistDownControl = NULL;
-
- while (twistDownElement != NULL && myOSErr == noErr)
- {
- ++rowNumber;
- if (twistDownElement -> TestHasSubListFlag() && twistDownElement -> GetTwistDownControl() == NULL)
- {
- short rowHeight = this -> GetRowHeight(1);
- twistDownControlLocation.v = (long)(rowHeight*rowNumber - rowHeight);
- twistDownControlLocation.h = fTwistDownControlLocation.h;
- twistDownControl = this -> NewTwistDownControl(twistDownElement, twistDownControlLocation, myOSErr);
- twistDownElement -> SetTwistDownControlTo(twistDownControl);
- }
-
- if (myOSErr == noErr)
- {
- if (twistDownElement -> TestShowSubListFlag())
- this -> AddTwistDownControls(twistDownElement -> GetDescendantElement(), rowNumber, myOSErr);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DeleteTwistDownControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::DeleteTwistDownControls(TTwistDownElement* twistDownElement)
- {
-
- while (twistDownElement != NULL)
- {
- //Never remove twistDownControls from twistDownElements whose fIndentLevel == 0 because
- //these elements are at the top of the hierarchy. Remove them and the user will never
- //be able to descend the hierarchy.
-
- if (twistDownElement -> GetTwistDownControl() != NULL && twistDownElement -> GetIndentLevel() != 0)
- this -> RemoveTwistDownControl(twistDownElement);
-
- //There are no hidden twistDownControls. The only twistDownControls that exist
- //are the ones you can see in the twistDownView. However, twistDownElements can have
- //their fShowSubList set to TRUE even if they don't have a twistDownControl.
- //Deleting a twistDowncontrol does not change the value of fShowSubList.
-
- if (twistDownElement -> TestShowSubListFlag())
- this -> DeleteTwistDownControls(twistDownElement -> GetDescendantElement());
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::RestoreTwistDownControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::RestoreTwistDownControls(TTwistDownElement* twistDownElement)
- {
- while (twistDownElement != NULL)
- {
- //Never remove twistDownControls from twistDownElements whose fIndentLevel == 0 because
- //these elements are at the top of the hierarchy. Remove them and the user will never
- //be able to descend the hierarchy.
-
- if (twistDownElement -> GetTwistDownControl() != NULL
- && twistDownElement -> GetIndentLevel() != 0
- && twistDownElement -> TestOldShowSubListFlag() != FALSE)
- {
- this -> RemoveTwistDownControl(twistDownElement);
- }
-
- if (twistDownElement -> TestShowSubListFlag())
- this -> DeleteTwistDownControls(twistDownElement -> GetDescendantElement());
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::RemoveTwistDownControl:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::RemoveTwistDownControl(TTwistDownElement* twistDownElement)
- {
- TTwistDownControl* twistDownControl = NULL;
-
- twistDownControl = twistDownElement -> GetTwistDownControl();
-
- if (twistDownElement -> TestShowSubListFlag())
- {
- fNumberOfExpandedControls--; //We're removing a control that was expanded.
- }
- else
- fNumberOfCollapsedControls--; //We're removing a control that was collapsed.
-
- this -> RemoveSubView(twistDownControl);
- twistDownControl = (TTwistDownControl*)FreeIfObject(twistDownControl);
-
- //Note: The TTwistDownControl::Free() method sets the fTwistDownControl field of
- //the twistDownElement to NULL;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::UpdateTwistDownControlLocations: called by TTwistDownDocument::ExpandElement
- // TTwistDownDocument::CollapseElement
- // TTwistDownDocument::CollapseAll
- // TExpandAllCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::UpdateTwistDownControlLocations(TTwistDownElement* twistDownElement, short &rowNumber)
- {
-
- while (twistDownElement != NULL)
- {
- ++rowNumber;
- TTwistDownControl* twistDownControl = twistDownElement -> GetTwistDownControl();
- if (twistDownControl != NULL)
- twistDownControl -> UpdateControlLocationTo(rowNumber);
-
- if (twistDownElement -> TestShowSubListFlag())
- this -> UpdateTwistDownControlLocations(twistDownElement -> GetDescendantElement(), rowNumber);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetItemTextToDisplay: replaces GetItemText (could have been overloaded)
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- short TTwistDownView::GetItemTextToDisplay(short anItem, CStr63& aString)
- {
- MAVolatileInit(TTwistDownElement*, theTwistDownElement, NULL);
- TTwistDownControl* twistDownControl = NULL;
-
- short rowNumber = 0;
- fTwistDownDocument -> GetTwistDownElementAt(anItem, fTwistDownDocument -> GetHeadOfList(), &theTwistDownElement, rowNumber);
- theTwistDownElement -> GetDisplayedText(aString);
- short indentLevel = theTwistDownElement -> GetIndentLevel();
- return indentLevel;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetTextToDisplay: replaces GetText (could have been overloaded)
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- short TTwistDownView::GetTextToDisplay(GridCell aCell, CStr63& aString)
- {
- short indentLevel = this -> GetItemTextToDisplay(aCell.v, aString); //replaces GetItemText
- return indentLevel;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DrawCell:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::DrawCell(GridCell aCell, const VRect& aRect)// override
- {
- CStr63 theText;
- short indentLevel;
-
- indentLevel = this -> GetTextToDisplay(aCell, theText); //replaces GetText
-
- if (this -> GetColWidth(aCell.h) > 0)
- {
- CRect r;
- short amountToIndent;
-
- amountToIndent = (indentLevel + 1)*fTwistDownControlSize.h; //We need to add 1 to the indentLevel
- //because the indentLevel of
- //twistDownControls at the top level
- //of the hierarchy is zero.
-
- this -> ViewToQDRect(aRect, r);
-
- //offset the rectangle here
- if (fWritingDirection == leftToRight)
- r.left = r.left + amountToIndent;
- else
- r.right = r.right - amountToIndent - 5;
-
- if(this->CanSelectCell(aCell))
- MADrawString(theText, r, fJustification, fPreferOutline);
- else
- {
- GrafPtr currentPort;
- GetPort(¤tPort);
-
- PenState pState;
- GetPenState(&pState); // save pen state
- short txMode = currentPort -> txMode;
-
- if (qNeedsColorQD || HasColorQD())
- TextMode(grayishTextOr);
-
- MADrawString(theText, r, fJustification, fPreferOutline);
-
- if (!(qNeedsColorQD || HasColorQD()))
- {
- PenPat(&qd.gray);
- PenMode(patBic);
- PaintRect(r);
- }
-
- SetPenState(&pState); // restore pen state
- TextMode(txMode);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- //TTwistDownView::GetNewFontSize:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- Boolean TTwistDownView::GetNewFontSize(CommandNumber aCommandNumber,long& newFontSize)
- {
- #pragma unused aCommandNumber
- Boolean result = FALSE;
- TChangeFontSizeDialog* aChangeFontSizeView = NULL;
- TWindow* aChangeFontSizeWindow = NULL;
- IDType dismisser;
-
- if (qTemplateViews)
- {
- FailNIL(aChangeFontSizeWindow = gViewServer -> NewTemplateWindow(kChangeFontSizeWindowID, NULL));
- aChangeFontSizeView = (TChangeFontSizeDialog*) (aChangeFontSizeWindow -> FindSubView(kChangeFontSizeViewID));
- aChangeFontSizeView -> SetNewSize(newFontSize);
- }
-
- if (aChangeFontSizeWindow != NULL)
- {
- dismisser = aChangeFontSizeWindow -> PoseModally();
-
- if (dismisser == kDefaultOKItemID)
- {
- aChangeFontSizeView -> GetNewFontSize(newFontSize);
- result = TRUE;
- }
-
- aChangeFontSizeWindow -> CloseAndFree();
- }
-
- return result;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoChangeTextStyle:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::DoChangeTextStyle(const TextStyle& itsTextStyle)
- {
- short rowHeight = 0;
-
- GrafPtr savedPort;
- GetPort(&savedPort); // save the port
- SetPort(gWorkPort); // set port to the work port
-
- SetPortTextStyle(itsTextStyle); // set the port's text style
- PenNormal();
-
- FontInfo theFontInfo;
- rowHeight = MAGetFontInfo(theFontInfo) + fRowInset;
-
- SetPort(savedPort); // restore port
-
- fTextStyle = itsTextStyle;
- this -> SetUpFont();
-
- this -> SetItemHeight(1,fNumOfRows,rowHeight);
- this -> CreateTwistDownTriangles();
-
- fTwistDownDocument -> InstallTextStyle(itsTextStyle);
-
- short rowNumber = 0;
-
- TTwistDownElement* headOfListElement = fTwistDownDocument -> GetHeadOfList();
- if ( headOfListElement)
- {
- fTwistDownDocument -> UpdateTwistDownElements(headOfListElement, rowNumber);
- this -> ResizeTwistDownViewRows();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoChangeFontSize:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::DoChangeFontSize(short newFontSize)
- {
- TextStyle newStyle = fTextStyle;
- newStyle.tsSize = newFontSize;
- this -> DoChangeTextStyle(newStyle);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoChangeFont:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::DoChangeFont(CStr255 newFontName)
- {
- short fontNumber = 0;
- GetFNum(newFontName, &fontNumber); //Moves memory. If it can't find newFontName, fontNumber
- //will be zero. The following if tests it and only does
- //the change if the font actually exists.
- if (fontNumber != 0)
- {
- TextStyle newStyle = fTextStyle;
- GetFNum(newFontName, &(newStyle.tsFont));
- this -> DoChangeTextStyle(newStyle);
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoChangeWritingDirection:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::DoChangeWritingDirection(EWritingDirection newWritingDirection)
- {
- fWritingDirection = newWritingDirection;
-
- if (fWritingDirection == leftToRight)
- fJustification = teFlushDefault;
- else
- fJustification = teFlushRight;
-
- this -> CreateTwistDownTriangles();
-
- short rowNumber = 0;
-
- TTwistDownElement* headOfListElement = fTwistDownDocument -> GetHeadOfList();
- if ( headOfListElement)
- {
- fTwistDownDocument -> UpdateTwistDownElements(headOfListElement, rowNumber);
-
- if (fWritingDirection == leftToRight)
- this -> RevealTop(kRedraw);
- else
- this -> RevealRight(kRedraw);
-
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetTwistDownControlSize:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- VPoint TTwistDownView::GetTwistDownControlSize()
- {
- return fTwistDownControlSize;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::CreateTwistDownTriangles:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::CreateTwistDownTriangles()
- {
- short twistDownControlSize;
- short halfSize;
- short intermediateSize;
- FontInfo theFontInfo;
- short theFontHeight;
- OSErr myQDError = noErr;
-
- theFontHeight = MAGetFontInfo(theFontInfo);
- fTwistDownControlSize.v = theFontHeight;
-
- twistDownControlSize = theFontInfo.ascent;
- twistDownControlSize &= ~1; /* Round down to an even number */
- halfSize = twistDownControlSize / 2;
- intermediateSize = (twistDownControlSize * 3) / 4;
-
- FailInfo fi;
- Try(fi)
- {
-
- //First, get rid of the existing triangles. The triangles do not exist for a new TTwistDownView.
- //However, when changing the format of the TTwistDownView, they do exist. Anytime the font or
- //its size are changed, the triangles are created again.
-
- if (fOpenTriangle)
- {
- KillPoly(fOpenTriangle);
- FailOSErr(QDError());
- fOpenTriangle = NULL;
- }
-
- if (fClosedTriangle)
- {
- KillPoly(fClosedTriangle);
- FailOSErr(QDError());
- fClosedTriangle = NULL;
- }
-
- if (fIntermediateTriangle)
- {
- KillPoly(fIntermediateTriangle);
- FailOSErr(QDError());
- fIntermediateTriangle = NULL;
- }
-
- fOpenTriangle = OpenPoly();
- FailOSErr(QDError());
- MoveTo(0, halfSize);
- LineTo(twistDownControlSize, halfSize);
- LineTo(halfSize, twistDownControlSize);
- LineTo(0, halfSize);
- ClosePoly();
- FailOSErr(QDError());
-
- fTwistDownControlSize.h = (**fOpenTriangle).polyBBox.right + kTriangleOutsideGap + kTriangleInsideGap;
-
- if (fWritingDirection == leftToRight)
- fTwistDownControlLocation.h = 0;
- else
- fTwistDownControlLocation.h = fSize.h - fTwistDownControlSize.h;
-
- //In a normal application, I would use
- // short sysDirection = GetSysDirection();
- // if (sysDirection == 0)
- //instead of
- // if (fWritingDirection == leftToRight)
- //That is because GetSysDirection() returns the system direction for the system font and
- //not the application font. Here we're testing so it is necessary to fake it and pretend
- //we're running on an Arabic or Hebrew system.
-
- if (fWritingDirection == leftToRight)
- {
- fClosedTriangle = OpenPoly();
- FailOSErr(QDError());
- MoveTo(halfSize, 0);
- LineTo(twistDownControlSize, halfSize);
- LineTo(halfSize, twistDownControlSize);
- LineTo(halfSize, 0);
- ClosePoly();
- FailOSErr(QDError());
-
- fIntermediateTriangle = OpenPoly();
- FailOSErr(QDError());
- MoveTo(intermediateSize, 0);
- LineTo(intermediateSize, intermediateSize);
- LineTo(0, intermediateSize);
- LineTo(intermediateSize, 0);
- ClosePoly();
- FailOSErr(QDError());
- }
- else /* Arabic/Hebrew triangles */
- {
-
- fClosedTriangle = OpenPoly();
- FailOSErr(QDError());
- MoveTo(twistDownControlSize - halfSize, 0);
- LineTo(0, halfSize);
- LineTo(twistDownControlSize - halfSize, twistDownControlSize);
- LineTo(twistDownControlSize - halfSize, 0);
- ClosePoly();
- FailOSErr(QDError());
-
- fIntermediateTriangle = OpenPoly();
- FailOSErr(QDError());
- MoveTo(twistDownControlSize - intermediateSize, 0);
- LineTo(twistDownControlSize - intermediateSize, intermediateSize);
- LineTo(twistDownControlSize, intermediateSize);
- LineTo(twistDownControlSize - intermediateSize, 0);
- ClosePoly();
- FailOSErr(QDError());
- }
- fi.Success();
- }
- else
- {
- if (fOpenTriangle)
- {
- KillPoly(fOpenTriangle);
- fOpenTriangle = NULL;
- }
-
- if (fClosedTriangle)
- {
- KillPoly(fClosedTriangle);
- fClosedTriangle = NULL;
- }
-
- if (fIntermediateTriangle)
- {
- KillPoly(fIntermediateTriangle);
- fIntermediateTriangle = NULL;
- }
-
- fi.ReSignal();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetOpenTriangle:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- PolyHandle TTwistDownView::GetOpenTriangle()
- {
- return fOpenTriangle;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetClosedTriangle:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- PolyHandle TTwistDownView::GetClosedTriangle()
- {
- return fClosedTriangle;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetIntermediateTriangle:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- PolyHandle TTwistDownView::GetIntermediateTriangle()
- {
- return fIntermediateTriangle;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::IncrementNumberOfControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::IncrementNumberOfControls()
- {
- fNumberOfControls++;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DecrementNumberOfControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::DecrementNumberOfControls()
- {
- fNumberOfControls--;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetNumberOfControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- long TTwistDownView::GetNumberOfControls()
- {
- return fNumberOfControls;
- }
-
- //----------------------------------------------------------------------------------------
- // TTwistDownView::IncrementNumberOfExpandedControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::IncrementNumberOfExpandedControls()
- {
- fNumberOfExpandedControls++;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DecrementNumberOfExpandedControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::DecrementNumberOfExpandedControls()
- {
- fNumberOfExpandedControls--;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::IncrementNumberOfCollapsedControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TTwistDownView::IncrementNumberOfCollapsedControls()
- {
- fNumberOfCollapsedControls++;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DecrementNumberOfCollapsedControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::DecrementNumberOfCollapsedControls()
- {
- fNumberOfCollapsedControls--;
- }
-
- //The following four methods are used to manage error recover from failed
- //TExpandAllCommands
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetNumberOfExpandedControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- long TTwistDownView::GetNumberOfExpandedControls()
- {
- return fNumberOfExpandedControls;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::SetNumberOfExpandedControlsTo:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::SetNumberOfExpandedControlsTo(long numberOfControls)
- {
- fNumberOfExpandedControls = numberOfControls;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetNumberOfCollapsedControls:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- long TTwistDownView::GetNumberOfCollapsedControls()
- {
- return fNumberOfCollapsedControls;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::SetNumberOfCollapsedControlsTo:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownView::SetNumberOfCollapsedControlsTo(long numberOfControls)
- {
- fNumberOfCollapsedControls = numberOfControls;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::SetCantExpandAll: used by TExpandAllCommand::DoIt:
- //----------------------------------------------------------------------------------------
- //This is called just after the ExpandAll command has been done.
- #pragma segment ADoCommand
- void TTwistDownView::SetCantExpandAll()
- {
- fNumberOfExpandedControls = fNumberOfControls;
- fNumberOfCollapsedControls = 0;
- this -> SetTheCouldFlags();
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::SetCantCollapseAll: used by TCollapseAllCommand::DoIt:
- //----------------------------------------------------------------------------------------
- //This is called just after the CollapseAll command has been done.
- #pragma segment ADoCommand
- void TTwistDownView::SetCantCollapseAll()
- {
- fNumberOfExpandedControls = 0;
- fNumberOfCollapsedControls = fNumberOfControls;
- this -> SetTheCouldFlags();
- }
-
- //----------------------------------------------------------------------------------------
- // TTwistDownView::SetTheCouldFlags: called by
- // TTwistDownView::CreateVisibleList: (when the list is first created)
- // TTwistDownView::SetCantExpandAll:
- // TTwistDownView::SetCantCollapseAll:
- // TTwistDownDocument::ExpandElement:
- // TTwistDownDocument::CollapseElement:
- // TTwistDownDocument::CollapseAll:
- // TExpandAllCommand::DoIt: (failure recovery part)
- // TCollapseElementCommand::DoIt()
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownView::SetTheCouldFlags()
- {
-
- fCouldExpandAll = FALSE;
- fCouldCollapseAll = FALSE;
-
- if (fNumberOfExpandedControls > 0)
- fCouldCollapseAll = TRUE;
-
- if (fNumberOfCollapsedControls > 0 && fTwistDownDocument -> GetNumberOfItemsInList() <= (long)kMaxNumberOfItemsToDisplay)
- fCouldExpandAll = TRUE;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::IncrementInitialNumberOfControls: Used
- //----------------------------------------------------------------------------------------
- //This is used only by TTwistDownControl::ITwistDownControl and then only if
- //TTwistDownView::ControlCountingEnabled() returns FALSE.
- #pragma segment AOpen
- void TTwistDownView::IncrementInitialNumberOfControls()
- {
- fInitialNumberOfControls++;
- }
-
- //----------------------------------------------------------------------------------------
- // TTwistDownView::ControlCountingEnabled:
- //----------------------------------------------------------------------------------------
- //This is used only by TTwistDownControl::ITwistDownControl.
- //Once the twistDownDocument has been read in and the intiial controls have been made,
- //fControlCountingEnabled is set to TRUE for the life of the twistDownDocument.
- #pragma segment ARes
- Boolean TTwistDownView::ControlCountingEnabled()
- {
- return fControlCountingEnabled;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TTwistDownView::DoScriptCommand: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownView::DoScriptCommand(CommandNumber aCommandNumber, TAppleEvent* message, TAppleEvent* reply)
- {
-
- switch (aCommandNumber)
- {
- case cExpandAll:
- {
- if (fCouldExpandAll) //See note in TTwistDownDocument::DoScriptCommand
- {
- long objectHeapSpaceRequired = long((fTwistDownDocument -> GetNumberOfDirectoriesInList()
- - fNumberOfControls)*(gTwistDownApp -> fTDControlClassSize));
-
- Boolean haveHeapSpace = HaveObjectHeapSpace(objectHeapSpaceRequired + 3*1024);
-
- if (haveHeapSpace)
- {
- TExpandAllCommand* anExpandAllCommand = new TExpandAllCommand;
- anExpandAllCommand -> IExpandAllCommand(fTwistDownDocument,this,
- message -> fMessage, reply -> fMessage);
-
- this -> PostCommand(anExpandAllCommand);
- }
- else
- Failure(memFullErr, 0);
- }
- else
- FailOSErr(errListAlreadyExpanded);
- }
- break;
-
- case cCollapseAll:
- {
- if (fCouldCollapseAll)
- {
- //Because we don't want this to fail for out of memory reasons,
- //allocate it from temporary memory. //PGMacApp 550
- Boolean oldTemp = TemporaryAllocation(TRUE);
- Boolean oldArrayPerm = AllocateObjectsFromPerm(FALSE);
- TCollapseAllCommand* aCollapseAllCommand = new TCollapseAllCommand;
- aCollapseAllCommand -> ICollapseAllCommand(fTwistDownDocument, this,
- message -> fMessage, reply -> fMessage);
-
- this -> PostCommand(aCollapseAllCommand);
- oldArrayPerm = AllocateObjectsFromPerm(oldArrayPerm);
- oldTemp = TemporaryAllocation(oldTemp);
- }
- else
- FailOSErr(errListAlreadyCollapsed);
- }
- break;
-
- default:
- {
- MScriptableObject::DoScriptCommand(aCommandNumber, message, reply);
- }
- break;
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetSpecifierForm: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- DescType TTwistDownView::GetSpecifierForm()
- {
- return formName;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetObjectProperty: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- Boolean TTwistDownView::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
- // Return properties for the twistDownView
-
- Boolean hasProperty = TRUE;
-
- FailInfo fi;
- Try(fi)
- {
- switch (whichProperty)
- {
-
- case pName:
- CStr255 theName;
- theName = fTwistDownDocument -> fTitle;
- thePropertyValue.PutString(theName);
- break;
-
- case pFontName:
- CStr255 theFontName;
- short theFontNum = fTextStyle.tsFont;
- GetFontName(theFontNum, theFontName);
- thePropertyValue.PutString(theFontName);
- break;
-
- case pPointSize:
- long itsSize = (long)fTextStyle.tsSize;
- thePropertyValue.PutLong(itsSize);
- break;
-
- case pCouldExpand:
- thePropertyValue.PutBoolean(fCouldExpandAll);
- break;
-
- case pCouldCollapse:
- thePropertyValue.PutBoolean(fCouldCollapseAll);
- break;
-
- case pWritingDirection:
- {
- DescType theWritingDirection;
-
- if (fWritingDirection == leftToRight)
- theWritingDirection = kAELeftToRight;
- else if (fWritingDirection == rightToLeft)
- theWritingDirection = kAERightToLeft;
-
- thePropertyValue.PutEnum(theWritingDirection);
- }
- break;
-
- default:
- hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- break;
- }
- fi.Success();
- }
- else
- {
- // we failed while trying to get the property
- hasProperty = FALSE;
-
- // Don't ReSignal
- }
- return hasProperty;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::GetSetPropertyInfo: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownView::GetSetPropertyInfo(DescType whichProperty,
- CommandNumber& cmdNum,
- Boolean& canUndo,
- Boolean& causesChange,
- TCommandHandler* &theContext)
- {
-
- switch(whichProperty)
- {
-
- case pFontName:
- cmdNum = cChangeFont;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pPointSize:
- cmdNum = cChangeFontSize;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pWritingDirection:
- cmdNum = cChangeWritingDirection;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- default:
- MScriptableObject::GetSetPropertyInfo(whichProperty, cmdNum, canUndo, causesChange, theContext);
- break;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownView::SetObjectProperty: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownView::SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty)
- {
- //I'm ambivalent about whether it makes sense to allow a script to change the font, its size,
- //or the writing direction if the list is empty. We wouldn't allow it from the menu. For the
- //sake of argument, let's not allow it here but allow it in TTwistDownDocument::SetObjectProperty.
- long numberOfItemsInList = 0;
-
- if (fTwistDownDocument)
- numberOfItemsInList = fTwistDownDocument -> GetNumberOfItemsInList();
-
- switch (whichProperty)
- {
- case pName:
- CStr255 theDocName;
- thePropertyValue.GetString(theDocName);
- fTwistDownDocument -> SetTitle(theDocName);
- break;
-
- case pFontName:
- CStr255 newFontName;
- thePropertyValue.GetString(newFontName,255);
- if (numberOfItemsInList > 0)
- this -> DoChangeFont(newFontName);
- break;
-
- case pPointSize:
- short newFontSize = 0;
- newFontSize = (short)thePropertyValue.GetLong();
- if (numberOfItemsInList > 0)
- this -> DoChangeFontSize(newFontSize);
- break;
-
- case pWritingDirection:
- {
- DescType theWritingDirection = thePropertyValue.GetEnum();
- EWritingDirection newWritingDirection = leftToRight;
-
- if (theWritingDirection == kAELeftToRight)
- newWritingDirection = leftToRight;
- else
- newWritingDirection = rightToLeft;
-
- //From a script, it is possible to tell a twistDownView to change
- //the writing direction to the same writing direction, ie. no change.
- //Here we make sure it is actually going to change before proceeding.
- if (newWritingDirection != fWritingDirection && numberOfItemsInList > 0)
- this -> DoChangeWritingDirection(newWritingDirection);
-
- }
- break;
-
- default:
- MScriptableObject::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
- //========================================================================================
- // CLASS TChangeFontSizeDialog
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment ADoCommand
- MA_DEFINE_CLASS_M1(TChangeFontSizeDialog, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TChangeFontSizeDialog constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
- TChangeFontSizeDialog::TChangeFontSizeDialog()
- {
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TChangeFontSizeDialog::~TChangeFontSizeDialog
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- TChangeFontSizeDialog::~TChangeFontSizeDialog()
- {
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TChangeFontSizeDialog::IChangeFontSizeDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TChangeFontSizeDialog::IChangeFontSizeDialog(TDocument* itsDocument,TView* itsSuperView,
- const VPoint& itsLocation,const VPoint& itsSize,SizeDeterminer itsHSizeDet,SizeDeterminer itsVSizeDet)
- {
- this -> IView(itsDocument,itsSuperView,itsLocation,itsSize,itsHSizeDet,itsVSizeDet);
-
- }
- //----------------------------------------------------------------------------------------
- // TChangeFontSizeDialog::GetNewFontSize:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TChangeFontSizeDialog::GetNewFontSize(long& newSize)
- {
- TNumberText* fontSizeValue = NULL;
-
- fontSizeValue = (TNumberText*) (this -> FindSubView(kSizeValueViewID));
- newSize = fontSizeValue -> GetValue();
- }
- //----------------------------------------------------------------------------------------
- // TChangeFontSizeDialog::SetNewSize:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TChangeFontSizeDialog::SetNewSize(long& newSize)
- {
- TNumberText* fontSizeValue = NULL;
-
- fontSizeValue = (TNumberText*) (this -> FindSubView(kSizeValueViewID));
- fontSizeValue -> SetValue(newSize, TRUE);
- }
-
-
-
- #pragma segment Inline